using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VSYSREIT
    {
        public DataRow Convert2SYSREIT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySYSREIT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["SYRMANDANT"] = " ".PadRight(2 ); 
         dwReturn["SYRPROG"] = " ".PadRight(8 ); 
         dwReturn["SYRFOLGENR"] = " ".PadRight(2 ); 
         dwReturn["SYRSPRKZ"] = " ".PadRight(1 ); 
         dwReturn["SYRHE1"] = " ".PadRight(1 ); 
         dwReturn["SYRRF1"] = " ".PadRight(3 ); 
         dwReturn["SYRVG1"] = " ".PadRight(1 ); 
         dwReturn["SYRDF1"] = " ".PadRight(2 ); 
         dwReturn["SYRICO1"] = " ".PadRight(2 ); 
         dwReturn["SYRTEXT1"] = " ".PadRight(30 ); 
         dwReturn["SYRNAME1"] = " ".PadRight(8 ); 
         dwReturn["SYRWERT1"] = " ".PadRight(8 ); 
         dwReturn["SYRRESERVE1"] = " ".PadRight(16 ); 
         dwReturn["SYRHE2"] = " ".PadRight(1 ); 
         dwReturn["SYRRF2"] = " ".PadRight(3 ); 
         dwReturn["SYRVG2"] = " ".PadRight(1 ); 
         dwReturn["SYRDF2"] = " ".PadRight(2 ); 
         dwReturn["SYRICO2"] = " ".PadRight(2 ); 
         dwReturn["SYRTEXT2"] = " ".PadRight(30 ); 
         dwReturn["SYRNAME2"] = " ".PadRight(8 ); 
         dwReturn["SYRWERT2"] = " ".PadRight(8 ); 
         dwReturn["SYRRESERVE2"] = " ".PadRight(16 ); 
         dwReturn["SYRTAB1"] = " ".PadRight(700 ); 
         dwReturn["SYRTAB2"] = " ".PadRight(700 ); 
         dwReturn["SYRTAB3"] = " ".PadRight(588 ); 
         dwReturn["SYRFILLER"] = " ".PadRight(231 ); 
         dwReturn["SYRAEND"] = " ".PadRight(0 ); 
         dwReturn["SYRAENB"] = " ".PadRight(8 ); 
         dwReturn["SYRNEUD"] = " ".PadRight(0 ); 
         dwReturn["SYRNEUB"] = " ".PadRight(8 ); 
         dwReturn["SYRAENZL"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapSYSREIT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveSYSREIT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerySYSREIT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSYSREIT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertSYSREIT(dwLocal, ITXDBVERSION);
            }
            UpdateSYSREIT(dwLocal);
        }
        public void InsertSYSREIT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO SYSREIT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QuerySYSREIT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM SYSREIT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM SYSREIT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "SYSREIT";
            Return = Result;
            return Return;
        }
        public void DeleteSYSREIT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM SYSREIT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateSYSREIT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE SYSREIT SET "
                    +"SYRMANDANT= :SYRMANDANT,"
                    +"SYRPROG= :SYRPROG,"
                    +"SYRFOLGENR= :SYRFOLGENR,"
                    +"SYRSPRKZ= :SYRSPRKZ,"
                    +"SYRHE1= :SYRHE1,"
                    +"SYRRF1= :SYRRF1,"
                    +"SYRVG1= :SYRVG1,"
                    +"SYRDF1= :SYRDF1,"
                    +"SYRICO1= :SYRICO1,"
                    +"SYRTEXT1= :SYRTEXT1,"
                    +"SYRNAME1= :SYRNAME1,"
                    +"SYRWERT1= :SYRWERT1,"
                    +"SYRRESERVE1= :SYRRESERVE1,"
                    +"SYRHE2= :SYRHE2,"
                    +"SYRRF2= :SYRRF2,"
                    +"SYRVG2= :SYRVG2,"
                    +"SYRDF2= :SYRDF2,"
                    +"SYRICO2= :SYRICO2,"
                    +"SYRTEXT2= :SYRTEXT2,"
                    +"SYRNAME2= :SYRNAME2,"
                    +"SYRWERT2= :SYRWERT2,"
                    +"SYRRESERVE2= :SYRRESERVE2,"
                    +"SYRTAB1= :SYRTAB1,"
                    +"SYRTAB2= :SYRTAB2,"
                    +"SYRTAB3= :SYRTAB3,"
                    +"SYRFILLER= :SYRFILLER,"
                    +"SYRAEND= :SYRAEND,"
                    +"SYRAENB= :SYRAENB,"
                    +"SYRNEUD= :SYRNEUD,"
                    +"SYRNEUB= :SYRNEUB,"
                    +"SYRAENZL= :SYRAENZL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("SYRMANDANT", OracleType.NVarChar).Value = dwData["SYRMANDANT"].ToString(); 
          or1.Parameters.Add("SYRPROG", OracleType.NVarChar).Value = dwData["SYRPROG"].ToString(); 
          or1.Parameters.Add("SYRFOLGENR", OracleType.NVarChar).Value = dwData["SYRFOLGENR"].ToString(); 
          or1.Parameters.Add("SYRSPRKZ", OracleType.NVarChar).Value = dwData["SYRSPRKZ"].ToString(); 
          or1.Parameters.Add("SYRHE1", OracleType.NVarChar).Value = dwData["SYRHE1"].ToString(); 
          or1.Parameters.Add("SYRRF1", OracleType.NVarChar).Value = dwData["SYRRF1"].ToString(); 
          or1.Parameters.Add("SYRVG1", OracleType.NVarChar).Value = dwData["SYRVG1"].ToString(); 
          or1.Parameters.Add("SYRDF1", OracleType.NVarChar).Value = dwData["SYRDF1"].ToString(); 
          or1.Parameters.Add("SYRICO1", OracleType.NVarChar).Value = dwData["SYRICO1"].ToString(); 
          or1.Parameters.Add("SYRTEXT1", OracleType.NVarChar).Value = dwData["SYRTEXT1"].ToString(); 
          or1.Parameters.Add("SYRNAME1", OracleType.NVarChar).Value = dwData["SYRNAME1"].ToString(); 
          or1.Parameters.Add("SYRWERT1", OracleType.NVarChar).Value = dwData["SYRWERT1"].ToString(); 
          or1.Parameters.Add("SYRRESERVE1", OracleType.NVarChar).Value = dwData["SYRRESERVE1"].ToString(); 
          or1.Parameters.Add("SYRHE2", OracleType.NVarChar).Value = dwData["SYRHE2"].ToString(); 
          or1.Parameters.Add("SYRRF2", OracleType.NVarChar).Value = dwData["SYRRF2"].ToString(); 
          or1.Parameters.Add("SYRVG2", OracleType.NVarChar).Value = dwData["SYRVG2"].ToString(); 
          or1.Parameters.Add("SYRDF2", OracleType.NVarChar).Value = dwData["SYRDF2"].ToString(); 
          or1.Parameters.Add("SYRICO2", OracleType.NVarChar).Value = dwData["SYRICO2"].ToString(); 
          or1.Parameters.Add("SYRTEXT2", OracleType.NVarChar).Value = dwData["SYRTEXT2"].ToString(); 
          or1.Parameters.Add("SYRNAME2", OracleType.NVarChar).Value = dwData["SYRNAME2"].ToString(); 
          or1.Parameters.Add("SYRWERT2", OracleType.NVarChar).Value = dwData["SYRWERT2"].ToString(); 
          or1.Parameters.Add("SYRRESERVE2", OracleType.NVarChar).Value = dwData["SYRRESERVE2"].ToString(); 
          or1.Parameters.Add("SYRTAB1", OracleType.NVarChar).Value = dwData["SYRTAB1"].ToString(); 
          or1.Parameters.Add("SYRTAB2", OracleType.NVarChar).Value = dwData["SYRTAB2"].ToString(); 
          or1.Parameters.Add("SYRTAB3", OracleType.NVarChar).Value = dwData["SYRTAB3"].ToString(); 
          or1.Parameters.Add("SYRFILLER", OracleType.NVarChar).Value = dwData["SYRFILLER"].ToString(); 
          or1.Parameters.Add("SYRAEND", OracleType.NVarChar).Value = dwData["SYRAEND"].ToString(); 
          or1.Parameters.Add("SYRAENB", OracleType.NVarChar).Value = dwData["SYRAENB"].ToString(); 
          or1.Parameters.Add("SYRNEUD", OracleType.NVarChar).Value = dwData["SYRNEUD"].ToString(); 
          or1.Parameters.Add("SYRNEUB", OracleType.NVarChar).Value = dwData["SYRNEUB"].ToString(); 
          or1.Parameters.Add("SYRAENZL", OracleType.NVarChar).Value = dwData["SYRAENZL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
